package Form;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JButton;

import Control.CommonControls;
import Control.NeedyResident_DeleteUser_Control;
import Entity.NeedyResident_DeleteAccount;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class NeedyResident_DeleteUser_Form extends JPanel {
	
	NeedyResident_DeleteUser_Control controller;
	
	private JLabel lblNewLabel;
	private JLabel lblNewLabel_1;
	private JLabel lblDateOfBirth;
	private JLabel lblContactNumber;
	private JLabel lblEmail;
	private JLabel lbl_nric;
	private JLabel lbl_name;
	private JLabel lbl_dob;
	private JLabel lbl_contactNo;
	private JLabel lbl_email;
	private JButton bn_delete;
	public NeedyResident_DeleteUser_Form() {
		
		controller = new NeedyResident_DeleteUser_Control(this);
		//NeedyResident_DeleteAccount resident = controller.DeleteInfo();
		
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
		gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel.gridx = 2;
		gbc_lblNewLabel.gridy = 2;
		add(getLblNewLabel(), gbc_lblNewLabel);
		GridBagConstraints gbc_lbl_nric = new GridBagConstraints();
		gbc_lbl_nric.insets = new Insets(0, 0, 5, 5);
		gbc_lbl_nric.gridx = 3;
		gbc_lbl_nric.gridy = 2;
		add(getLbl_nric(), gbc_lbl_nric);
		GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
		gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_1.gridx = 2;
		gbc_lblNewLabel_1.gridy = 3;
		add(getLblNewLabel_1(), gbc_lblNewLabel_1);
		GridBagConstraints gbc_lbl_name = new GridBagConstraints();
		gbc_lbl_name.insets = new Insets(0, 0, 5, 5);
		gbc_lbl_name.gridx = 3;
		gbc_lbl_name.gridy = 3;
		add(getLbl_name(), gbc_lbl_name);
		GridBagConstraints gbc_lblDateOfBirth = new GridBagConstraints();
		gbc_lblDateOfBirth.insets = new Insets(0, 0, 5, 5);
		gbc_lblDateOfBirth.gridx = 2;
		gbc_lblDateOfBirth.gridy = 4;
		add(getLblDateOfBirth(), gbc_lblDateOfBirth);
		GridBagConstraints gbc_lbl_dob = new GridBagConstraints();
		gbc_lbl_dob.insets = new Insets(0, 0, 5, 5);
		gbc_lbl_dob.gridx = 3;
		gbc_lbl_dob.gridy = 4;
		add(getLbl_dob(), gbc_lbl_dob);
		GridBagConstraints gbc_lblContactNumber = new GridBagConstraints();
		gbc_lblContactNumber.insets = new Insets(0, 0, 5, 5);
		gbc_lblContactNumber.gridx = 2;
		gbc_lblContactNumber.gridy = 5;
		add(getLblContactNumber(), gbc_lblContactNumber);
		GridBagConstraints gbc_lbl_contactNo = new GridBagConstraints();
		gbc_lbl_contactNo.insets = new Insets(0, 0, 5, 5);
		gbc_lbl_contactNo.gridx = 3;
		gbc_lbl_contactNo.gridy = 5;
		add(getLbl_contactNo(), gbc_lbl_contactNo);
		GridBagConstraints gbc_lblEmail = new GridBagConstraints();
		gbc_lblEmail.insets = new Insets(0, 0, 5, 5);
		gbc_lblEmail.gridx = 2;
		gbc_lblEmail.gridy = 6;
		add(getLblEmail(), gbc_lblEmail);
		GridBagConstraints gbc_lbl_email = new GridBagConstraints();
		gbc_lbl_email.insets = new Insets(0, 0, 5, 5);
		gbc_lbl_email.gridx = 3;
		gbc_lbl_email.gridy = 6;
		add(getLbl_email(), gbc_lbl_email);
		GridBagConstraints gbc_bn_delete = new GridBagConstraints();
		gbc_bn_delete.gridx = 4;
		gbc_bn_delete.gridy = 7;
		add(getBn_delete(), gbc_bn_delete);
	}

	public JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("Nric:");
		}
		return lblNewLabel;
	}
	public JLabel getLblNewLabel_1() {
		if (lblNewLabel_1 == null) {
			lblNewLabel_1 = new JLabel("Name:");
		}
		return lblNewLabel_1;
	}
	public JLabel getLblDateOfBirth() {
		if (lblDateOfBirth == null) {
			lblDateOfBirth = new JLabel("Date Of Birth:");
		}
		return lblDateOfBirth;
	}
	public JLabel getLblContactNumber() {
		if (lblContactNumber == null) {
			lblContactNumber = new JLabel("Contact Number");
		}
		return lblContactNumber;
	}
	public JLabel getLblEmail() {
		if (lblEmail == null) {
			lblEmail = new JLabel("Email:");
		}
		return lblEmail;
	}
	public JLabel getLbl_nric() {
		if (lbl_nric == null) {
			lbl_nric = new JLabel(CommonControls.getUser().getNric());
		}
		return lbl_nric;
	}
	public JLabel getLbl_name() {
		if (lbl_name == null) {
			lbl_name = new JLabel(CommonControls.getUser().getName());
		}
		return lbl_name;
	}
	public JLabel getLbl_dob() {
		if (lbl_dob == null) {
			lbl_dob = new JLabel(CommonControls.getUser().getDob().toString());
		}
		return lbl_dob;
	}
	public JLabel getLbl_contactNo() {
		if (lbl_contactNo == null) {
			lbl_contactNo = new JLabel(Integer.toString(CommonControls.getUser().getContact_no()));
		}
		return lbl_contactNo;
	}
	public JLabel getLbl_email() {
		if (lbl_email == null) {
			lbl_email = new JLabel(CommonControls.getUser().getEmail());
		}
		return lbl_email;
	}
	public JButton getBn_delete() {
		if (bn_delete == null) {
			bn_delete = new JButton("Delete Account");
			bn_delete.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					controller.DeleteAccount();
					JOptionPane.showMessageDialog(null, "Account has been successfull deleted");
					NeedyResident_UpdateUser_Form.dialog.dispose();
					Main.frame.dispose();
					
					JFrame frame = new JFrame();
					frame.setTitle("Login");
					frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					JPanel contentPane = new JPanel();
					
					Customer_LogIn start = new Customer_LogIn(frame);
					contentPane.add(start);
					frame.setContentPane(contentPane);

					//Dynamically set size
					frame.pack();
					frame.setSize(frame.getWidth(), frame.getHeight());
					
					//Set frame to middle
					frame.setLocationRelativeTo(null);
					frame.setVisible(true);
				}
			});
		}
		return bn_delete;
	}
}
